<?php

defined('SYSPATH') or die('Access error!');

class Model_Trade_Template extends Model
{

    
    
    /**
     * 插入模板
     * @param type $data
     * @return type
     */
    public function insert_trade_template($data)
    {
        if (isset($data['category_id']))
        {
            $this->delete(array('category_id' => $data['category_id']));
        }
        return $this->insert($data);
    }
    
    
    
    /**
     * 获取模板列表
     * @param type $where_sql
     * @param type $nums
     * @return type
     */
    public function get_trade_template_list($where_sql = '', $nums = 10)
    {
        if (Arr::validate_arr($where_sql))
        {
            $where_sql = $this->get_table_where('tt', $where_sql);
        }
        $where_sql .= " ORDER BY tt.id DESC ";
        $sql = 'SELECT tt.*,c.name as category_name FROM ' . $this->table . ' AS tt ' .
                'LEFT JOIN ' . $this->db->get_table('category') . ' AS c ON c.id= tt.category_id ' . $where_sql;
        $data = $this->get_page_list($sql, $nums);
        return $data;
    }

}